package beans.taskprocess;

class TaskNode
{
	public static final int STATUS_WAITING = -1;
	public static final int STATUS_RUNNING = 0;
	public static final int STATUS_FINISHED = 1;

	private final Task __task;
	private final long __timeout;
	private int __status;
	private long __startTime;

	TaskNode(Task task, long timeout)
	{
		__task = task;
		__timeout = timeout;
		__status = STATUS_WAITING;
	}

	void doTask()
	{
		__status = STATUS_RUNNING;
		try
		{
			__startTime = System.currentTimeMillis();
			__task.toDo();
		}
		finally
		{
			__status = STATUS_FINISHED;
		}
	}

	boolean isTimeouted()
	{
		return __startTime + __timeout > System.currentTimeMillis();
	}

	int status()
	{
		return __status;
	}

	@Override
	public boolean equals(Object object)
	{
		return (object == this) || ((object instanceof TaskNode) && this.__equals((TaskNode) object));
	}

	public boolean equals(TaskNode taskNode)
	{
		return (taskNode == this) || this.__equals(taskNode);
	}

	private boolean __equals(TaskNode taskNode)
	{
		return __task.equals(taskNode.__task);
	}
}
